import axios from 'axios'
const newAxios = axios.create({
  baseURL: 'http://127.0.0.1:5000/api/',
  timeout: 5000
})
newAxios.interceptors.request.use(config => {
  // const token = window.sessionStorage.getItem('token')
  const token = getCookie('token')
  console.log(token)
  // if (token) {
  config.headers.Authorization = 'Bearer ' + token

  return config
  // }
})

function getCookie(cname) {
  const name = cname + '='
  const ca = document.cookie.split(';')
  for (let i = 0; i < ca.length; i++) {
    const c = ca[i].trim()
    if (c.indexOf(name) === 0) return c.substring(name.length, c.length)
  }
  return ''
}
export default newAxios
